import Vue from 'vue'
import VueI18n from 'vue-i18n'

Vue.use(VueI18n)
// 框架 国际化文件
import zh_cn from './lang/zh-CN'
import en from './lang/en'
export const messages: { [key: string]: any } = {
  'zh-CN': {
    langName: '简体中文',
    message: {
      ...zh_cn
    }
  },
  en: {
    langName: 'English',
    message: {
      ...en
    }
  }
}

const getQueryParams = (): { [key: string]: string | undefined } => {
  const params: { [key: string]: string | undefined } = {};
  const queryString = window.location.search.substring(1);
  const vars = queryString.split("&");
  for (let i = 0; i < vars.length; i++) {
    const pair = vars[i].split("=");
    params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
  }
  return params;
}

// 返回当前language
function getLanguage() {
  let lang = getQueryParams().lang as string
  // 默认语言为英文
  return lang || 'en'
}

export const i18n = new VueI18n({
  locale: getLanguage(), // 设置地区
  messages, // 设置地区信息
})


